import 'package:bilibili_getx_project/core/router/router.dart';
import 'package:bilibili_getx_project/core/shared_preference/bilibili_shared_preference.dart';
import 'package:bilibili_getx_project/core/shared_preference/shared_preference_util.dart';
import 'package:bilibili_getx_project/core/system_ui_overlay_style/system_ui_overlay_style_util.dart';
import 'package:bilibili_getx_project/ui/pages/functions/video_player_example/video_player_example_view.dart';
import 'package:bilibili_getx_project/ui/shared/app_theme.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'dart:ui' as ui;

import 'core/I18n/string_res.dart';

void main() async{
  if (kIsWeb) {
    ///web
    ScreenUtil.ensureScreenSize();
    SharedPreferenceUtil.getInstance();
  } else {
    await ScreenUtil.ensureScreenSize();
    await SharedPreferenceUtil.getInstance();
    SystemUiOverlayStyleUtil.setWhiteSystemUiOverlayStyle();
  }
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      minTextAdapt: true,
      splitScreenMode: true,
      designSize: Size(360, 690),
      builder: (ctx, child) {
        String? locale =
            SharedPreferenceUtil.getString(BilibiliSharedPreference.locale);
        if (locale!.isEmpty) {
          SharedPreferenceUtil.setString(
              BilibiliSharedPreference.locale, ui.window.locale.languageCode);
        }
        return GetMaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'bilibili_getx_project',
          theme: AppTheme.normalTheme,
          navigatorObservers: [FlutterSmartDialog.observer],
          builder: FlutterSmartDialog.init(),
          getPages: BilibiliRouter.getPages,
          initialRoute: BilibiliRouter.initialRoute,
          translations: StringRes(),
          fallbackLocale: const Locale('zh', 'CN'),
          locale: locale == 'en'
              ? const Locale('en', 'US')
              : const Locale('zh', 'CN'),
          // fallbackLocale: const Locale('en', 'US'),
        );
      },
    );
  }
}
